/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ourgame.tankgame.control;

import com.ourgame.tankgame.control.tank.TankControl;
import com.jme3.bounding.BoundingBox;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;
import com.jme3.scene.shape.Box;

/**
 *
 * @author echoff
 */
public class BaseMoveSystem extends MoveSystem {

    TankControl tankControl;

    @Override
    public void onAnalog(String name, float value, float tpf) {
        super.onAnalog(name, value, tpf);
    }

    @Override
    public void moveAhead(boolean isPressed) {
        tankControl.accelerate(isPressed ? 100f : 0);
        System.out.println("moveAhead");
    }

    @Override
    public void moveBack(boolean isPressed) {
        tankControl.accelerate(isPressed ? -100f : 0);
        System.out.println("moveBack");
    }

    @Override
    public void turnRight(boolean isPressed) {
        tankControl.steer(isPressed ? -50f : 0);
        System.out.println("turnRight");
    }

    @Override
    public void turnLeft(boolean isPressed) {
        tankControl.steer(isPressed ? 50f : 0);
        System.out.println("turnLeft");
    }

    @Override
    public void brake(boolean isPressed) {
        System.out.println("brake");
    }

    @Override
    protected void controlUpdate(float tpf) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Control cloneForSpatial(Spatial spatial) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void initMoveSystem() {
        BoundingBox worldBound = (BoundingBox) spatial.getWorldBound();
        Vector3f extent = worldBound.getExtent(null);
        Geometry tankSimpleShape = new Geometry("tankSimpleShape", new Box(Vector3f.ZERO, extent));

        tankControl = new TankControl(CollisionShapeFactory.createDynamicMeshShape(tankSimpleShape), controler.getInputManager(), controler.getCam());
//        setupKeys(controler.inputManager);
        spatial.addControl(tankControl);
    }
}
